<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>参数设置</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
        <el-row :gutter="20">


            <el-col :span="13">
            <el-label>等级公式</el-label>
 
        </el-col>


      </el-row>
      <el-row>
         <el-col :span="5">
                <el-label>A=a*（15n2+75n-40）</el-label>
            </el-col>
</el-row>
      <el-row>
            <el-col :span="1">
                <el-label>a:</el-label>
            </el-col>
        <el-col :span="1">
             <el-input
            placeholder="a"
            v-model="level"

          >
          </el-input>
        </el-col>
      
      </el-row>

<el-divider></el-divider>

        <el-row :gutter="20">
            <el-col :span="13">
            <el-label>年龄区段：0-年龄1, 年龄1-年龄2, 年龄2-年龄3, 年龄3以上</el-label>
        </el-col>

      </el-row>

            <el-row :gutter="20">
        
            <el-col :span="1.5">
                <el-label>年龄1:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="年龄1"
            v-model="age1"

          >
          </el-input>
        </el-col>
<el-col :span="1">
            <el-label>&nbsp</el-label>   
        </el-col>
                    <el-col :span="1.5">
                <el-label>年龄2:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="年龄2"
            v-model="age2"

          >
          </el-input>
        </el-col>
<el-col :span="1">
            <el-label>&nbsp</el-label>   
        </el-col>
                    <el-col :span="1.5">
                <el-label>年龄3:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="年龄3"
            v-model="age3"

          >
          </el-input>
        </el-col>

      </el-row>
<el-divider></el-divider>

        <el-row :gutter="20">
            <el-col :span="13">
            <el-label>车速区段：0-速度1, 速度1-速度2, 速度2-速度3, 速度3-速度4, 速度4-速度5, 速度5以上</el-label>
        </el-col>

      </el-row>

            <el-row :gutter="20">
        
            <el-col :span="1.5">
                <el-label>速度1:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="速度1"
            v-model="speed1"

          >
          </el-input>
        </el-col>
<el-col :span="1">
            <el-label>&nbsp</el-label>   
        </el-col>
                    <el-col :span="1.5">
                <el-label>速度2:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="速度2"
            v-model="speed2"

          >
          </el-input>
        </el-col>
<el-col :span="1">
            <el-label>&nbsp</el-label>   
        </el-col>
                    <el-col :span="1.5">
                <el-label>速度3:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="速度3"
            v-model="speed3"

          >
          </el-input>
        </el-col>
<el-col :span="1">
            <el-label>&nbsp</el-label>   
        </el-col>
           <el-col :span="1.5">
                <el-label>速度4:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="速度4"
            v-model="speed4"

          >
          </el-input>
        </el-col>
<el-col :span="1">
            <el-label>&nbsp</el-label>   
        </el-col>
           <el-col :span="1.5">
                <el-label>速度5:</el-label>
            </el-col>
        <el-col :span="2">
             <el-input
            placeholder="速度5"
            v-model="speed5"

          >
          </el-input>
        </el-col>

      </el-row>

  <el-divider></el-divider>


        <el-row type="flex" justify="end">
            <el-button type="primary" @click="updateparam()" icon="el-icon-edit"
                        >确定修改</el-button>
            </el-row>
    </el-card>

  </div>
</template>

<script>

export default {
  data () {
    return {

      nowcontact: {},

      paramList1: [],
      paramList2:[],
      age1:0,
      age2:0,
      age3:0,
      speed1:0,
      speed2:0,
      speed3:0,
      speed4:0,
      speed5:0,

      level:0,

    }
  },
  created () {
    // 加载页面时 加载一次数据
    this.getparamList1()
    this.getparamList2()
  },
  methods: {
  
  async getparamList1 () {
      const { data: res } = await this.$http.get('param/getparam/age')
      if (res.code !== 200) return this.$message.error('Error:' + res.message)
      this.paramList1 = res.data
      this.age1 = this.paramList1[0].value
      this.age2 = this.paramList1[1].value
      this.age3 = this.paramList1[2].value

      const { data: res2 } = await this.$http.get('param/getparam/level')
      if (res2.code !== 200) return this.$message.error('Error:' + res.message)
      this.level = res2.data[0].value


    },

      async getparamList2 () {
      const { data: res } = await this.$http.get('param/getparam/speed')
      if (res.code !== 200) return this.$message.error('Error:' + res.message)
      this.paramList2 = res.data

      this.speed1 = this.paramList2[0].value
      this.speed2 = this.paramList2[1].value
      this.speed3 = this.paramList2[2].value
      this.speed4 = this.paramList2[3].value
      this.speed5 = this.paramList2[4].value

    },

    async updateparam () {
      const { data: res } = await this.$http.post(
        'param/updateparam',
        {
        'age1': this.age1, 
        'age2': this.age2, 
        'age3': this.age3, 
        'speed1': this.speed1, 
        'speed2': this.speed2, 
        'speed3': this.speed3, 
        'speed4': this.speed4, 
        'speed5': this.speed5, 
        'level':this.level

        }, {
          headers: {
            'content-type': 'application/json',
            'X-Request-With': 'XMLHttpRequest',
            'token': window.sessionStorage.getItem('token')
          }
        }
      )
      if (res.code !== 200) return this.$message.error('Error:' + res.message)
      this.getparamList1()
      this.getparamList2()
    },



  },
  filters: {

  }
}
</script>

<style lang="less" scope>
.el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0px;
      align:'center'
    }
  }

.el-label{
  align:'center'
}
</style>
